<style>
    .am-tabs-bd {
        z-index: 1;
    }
</style>
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title a m-cf">基础设置</div>
                </div>
                <form id="my-form" class="am-form tpl-form-line-form" enctype="multipart/form-data" method="post">
                <div class="widget-body am-fr">
                    <div class="widget-body">
                        <fieldset>
                            <div class="am-tabs am-margin-top" data-am-tabs="{noSwipe: 1}">
                                <ul class="am-tabs-nav am-nav am-nav-tabs">
                                    <li class="am-active"><a href="#tab1">站点设置</a></li>
                                    <li><a href="#tab2">上传设置</a></li>
                                    <li><a href="#tab3">短信设置</a></li>
                                    <li><a href="#tab4">小程序设置</a></li>
                                    <!-- <li><a href="#tab5">报修设置</a></li> -->
                                </ul>
                                <div class="am-tabs-bd">
                                    <!-- 基础 -->
                                    <div class="am-tab-panel am-active am-margin-top-lg" id="tab1">
                                        <div class="am-form-group">
                                            <label class="am-u-sm-3 am-form-label form-require"> 网站名称 </label>
                                            <div class="am-u-sm-9">
                                                <input type="text" class="tpl-form-input" name="site[site_name]"
                                                        value="<?= $info['site']['site_name'] ?>" required>
                                            </div>
                                        </div>
                                        <div class="am-form-group">
                                            <label class="am-u-sm-3 am-form-label form-require"> 网站地址 </label>
                                            <div class="am-u-sm-9">
                                                <input type="text" class="tpl-form-input" name="site[site_url]"
                                                        value="<?= $info['site']['site_url'] ?>">
                                            </div>
                                        </div>
                                        <div class="am-form-group">
                                            <label class="am-u-sm-3 am-form-label form-require"> 网站版权 </label>
                                            <div class="am-u-sm-9">
                                                <input type="text" class="tpl-form-input" name="site[copyright]"
                                                        value="<?= $info['site']['copyright'] ?>">
                                            </div>
                                        </div>

                                        <div class="am-form-group">
                                            <label class="am-u-sm-3 am-form-label form-require"> 网站LOGO </label>
                                            <div class="am-u-sm-9 am-u-end">
                                                <div class="am-form-file">
                                                    <button type="button"
                                                            class="upload-file am-btn am-btn-secondary am-radius">
                                                        <i class="am-icon-cloud-upload"></i> 选择图片
                                                    </button>
                                                    <div class="uploader-list am-cf">
                                                        <?php if ($info['site']['site_logo']): ?>
                                                            <div class="file-item">
                                                                <img src="<?= $info['site']['site_logo']['file_path'] ?>">
                                                                <input type="hidden" name="site[site_logo]"
                                                                    value="<?= $info['site']['site_logo']['file_id'] ?>">
                                                                <i class="iconfont icon-shanchu file-item-delete"></i>
                                                            </div>
                                                        <?php endif; ?>
                                                    </div>
                                                </div>
                                                <div class="help-block am-margin-top-sm">
                                                    <small>尺寸750x750像素以上，大小2M以下 (可拖拽图片调整显示顺序 )</small>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="am-form-group">
                                            <label class="am-u-sm-3 am-form-label form-require"> 审核版本 </label>
                                            <div class="am-u-sm-9">
                                                <input type="text" class="tpl-form-input" name="site[version]"
                                                        value="<?= $info['site']['version'] ?>">
                                            </div>
                                        </div>
                                        <div class="am-form-group">
                                            <label class="am-u-sm-3 am-form-label form-require"> 网站开关 </label>
                                            <div class="am-u-sm-9">
                                                <{html_radios1("site[site_status]",$yesRadio,$info.site.site_status)}>
                                            </div>
                                        </div>
                                    </div>
                                    <!-- 上传 -->
                                    <div class="am-tab-panel am-margin-top-lg" id="tab2">
                                        <div class="am-form-group">
                                            <label class="am-u-sm-3 am-form-label">
                                                默认上传方式
                                            </label>
                                            <div class="am-u-sm-9">
                                                <label class="am-radio-inline">
                                                    <input type="radio" name="storage[default]" value="local" data-am-ucheck
                                                        <?= $info['storage']['default'] === 'local' ? 'checked' : '' ?>> 本地 (不推荐)
                                                </label>
                                                <label class="am-radio-inline">
                                                    <input type="radio" name="storage[default]" value="aliyun" data-am-ucheck
                                                        <?= $info['storage']['default'] === 'aliyun' ? 'checked' : '' ?>> 阿里云OSS
                                                </label>
                                            </div>
                                        </div>
                                        <div id="aliyun"
                                            class="form-tab-group <?= $info['storage']['default'] === 'aliyun' ? 'active' : '' ?>">
                                            <div class="am-form-group">
                                                <label class="am-u-sm-3 am-form-label">
                                                    存储空间名称 <span class="tpl-form-line-small-title">Bucket</span>
                                                </label>
                                                <div class="am-u-sm-9">
                                                    <input type="text" class="tpl-form-input" name="storage[engine][aliyun][bucket]"
                                                        value="<?= $info['storage']['engine']['aliyun']['bucket'] ?>">
                                                </div>
                                            </div>
                                            <div class="am-form-group">
                                                <label class="am-u-sm-3 am-form-label">
                                                    存储目录名称 <span class="tpl-form-line-small-title">Upload</span>
                                                </label>
                                                <div class="am-u-sm-9">
                                                    <input type="text" class="tpl-form-input" name="storage[engine][aliyun][upload]"
                                                        value="<?= $info['storage']['engine']['aliyun']['upload'] ?>">
                                                </div>
                                            </div>
                                            <div class="am-form-group">
                                                <label class="am-u-sm-3 am-form-label"> AccessKeyId </label>
                                                <div class="am-u-sm-9">
                                                    <input type="text" class="tpl-form-input"
                                                        name="storage[engine][aliyun][access_key_id]"
                                                        value="<?= $info['storage']['engine']['aliyun']['access_key_id'] ?>">
                                                </div>
                                            </div>
                                            <div class="am-form-group">
                                                <label class="am-u-sm-3 am-form-label"> AccessKeySecret </label>
                                                <div class="am-u-sm-9">
                                                    <input type="text" class="tpl-form-input"
                                                        name="storage[engine][aliyun][access_key_secret]"
                                                        value="<?= $info['storage']['engine']['aliyun']['access_key_secret'] ?>">
                                                </div>
                                            </div>
                                            <div class="am-form-group">
                                                <label class="am-u-sm-3 am-form-label">
                                                    地域节点 <span class="tpl-form-line-small-title">Endpoint</span>
                                                </label>
                                                <div class="am-u-sm-9">
                                                    <input type="text" class="tpl-form-input"
                                                        name="storage[engine][aliyun][endpoint]"
                                                        value="<?= $info['storage']['engine']['aliyun']['endpoint'] ?>">
                                                    <small>请补全http:// 或 https://，例如：http://static.cloud.com</small>
                                                </div>
                                            </div>
                                            <div class="am-form-group">
                                                <label class="am-u-sm-3 am-form-label">
                                                    空间域名 <span class="tpl-form-line-small-title">Domain</span>
                                                </label>
                                                <div class="am-u-sm-9">
                                                    <input type="text" class="tpl-form-input"
                                                        name="storage[engine][aliyun][domain]"
                                                        value="<?= $info['storage']['engine']['aliyun']['domain'] ?>">
                                                    <small>请补全http:// 或 https://，例如：http://static.cloud.com</small>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <!-- 短信 -->
                                    <div class="am-tab-panel am-margin-top-lg" id="tab3">
                                        <div class="am-form-group">
                                            <label class="am-u-sm-3 am-form-label form-require">
                                                是否开启短信
                                            </label>
                                            <div class="am-u-sm-9">
                                                <label class="am-radio-inline">
                                                    <input type="radio" name="sms[status]" value="0" data-am-ucheck
                                                        <?= $info['sms']['status'] == '0' ? 'checked' : '' ?>>
                                                    关闭
                                                </label>
                                                <label class="am-radio-inline">
                                                    <input type="radio" name="sms[status]" value="1" data-am-ucheck
                                                        <?= $info['sms']['status'] == '1' ? 'checked' : '' ?>>
                                                    开启
                                                </label>
                                            </div>
                                        </div>
                                        <div id="sms"
                                            class="form-tab-group <?= $info['sms']['status'] == '1' ? 'active' : '' ?>">
                                            <input type="hidden" name="sms[default]" value="aliyun">
                                            <div class="am-form-group">
                                                <label class="am-u-sm-3 am-form-label form-require"> AccessKeyId </label>
                                                <div class="am-u-sm-9">
                                                    <input type="text" class="tpl-form-input" name="sms[engine][aliyun][AccessKeyId]"
                                                        value="<?= $info['sms']['engine']['aliyun']['AccessKeyId'] ?>" required>
                                                </div>
                                            </div>
                                            <div class="am-form-group">
                                                <label class="am-u-sm-3 am-form-label form-require"> AccessKeySecret </label>
                                                <div class="am-u-sm-9">
                                                    <input type="text" class="tpl-form-input"
                                                        name="sms[engine][aliyun][AccessKeySecret]"
                                                        value="<?= $info['sms']['engine']['aliyun']['AccessKeySecret'] ?>" required>
                                                </div>
                                            </div>
                                            <div class="am-form-group">
                                                <label class="am-u-sm-3 am-form-label form-require"> 短信签名 </label>
                                                <div class="am-u-sm-9">
                                                    <input type="text" class="tpl-form-input" name="sms[engine][aliyun][sign]"
                                                        value="<?= $info['sms']['engine']['aliyun']['sign'] ?>" required>
                                                </div>
                                            </div>
                                            <div class="am-form-group">
                                                <label class="am-u-sm-3 am-form-label form-require">
                                                    模板内容 <span class="tpl-form-line-small-title">Template Code</span>
                                                </label>
                                                <div class="am-u-sm-9">
                                                    <input type="text" class="tpl-form-input"
                                                        name="sms[engine][aliyun][order_pay][template_code]"
                                                        value="<?= $info['sms']['engine']['aliyun']['order_pay']['template_code'] ?>">
                                                    <small>例如：SMS_139800030</small>
                                                </div>
                                            </div>
                                            <div class="am-form-group">
                                                <div class="am-u-sm-9 am-u-sm-push-3">
                                                    <small>模板内容：您有一条新订单，订单号为：${order_no}，请注意查看。</small>
                                                </div>
                                            </div>
                                            <div class="am-form-group">
                                                <label class="am-u-sm-3 am-form-label form-require"> 接收手机号 </label>
                                                <div class="am-u-sm-9">
                                                    <input type="text" class="tpl-form-input"
                                                        name="sms[engine][aliyun][order_pay][accept_phone]"
                                                        value="<?= $info['sms']['engine']['aliyun']['order_pay']['accept_phone'] ?>">
                                                    <div class="help-block">
                                                        <small>注：如需填写多个手机号，可用英文逗号 <code>,</code> 隔开</small>
                                                    </div>
                                                    <div class="help-block">
                                                        <small>接收测试： <a class="j-sendTestMsg" data-msg-type="order_pay"
                                                                        href="javascript:void(0);">点击发送</a>
                                                        </small>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <!-- 小程序 -->
                                    <div class="am-tab-panel am-margin-top-lg" id="tab4">
                                        <div class="am-form-group">
                                            <label class="am-u-sm-3 am-form-label form-require">
                                                AppID <span class="tpl-form-line-small-title">小程序ID</span>
                                            </label>
                                            <div class="am-u-sm-9">
                                                <input type="text" class="tpl-form-input" name="wxapp[app_id]"
                                                    value="<?= $info['wxapp']['app_id'] ?>" required>
                                            </div>
                                        </div>
                                        <div class="am-form-group">
                                            <label class="am-u-sm-3 am-form-label form-require">
                                                AppSecret <span class="tpl-form-line-small-title">小程序密钥</span>
                                            </label>
                                            <div class="am-u-sm-9">
                                                <input type="password" class="tpl-form-input" name="wxapp[app_secret]"
                                                    value="<?= $info['wxapp']['app_secret'] ?>" required>
                                            </div>
                                        </div>
                                        <div class="widget-head am-cf">
                                            <div class="widget-title am-fl">微信支付设置</div>
                                        </div>
                                        <div class="am-form-group">
                                            <label class="am-u-sm-3 am-form-label form-require">
                                                微信支付商户号 <span class="tpl-form-line-small-title">MCHID</span>
                                            </label>
                                            <div class="am-u-sm-9">
                                                <input type="text" class="tpl-form-input" name="wxapp[mchid]"
                                                    value="<?= $info['wxapp']['mchid'] ?>">
                                            </div>
                                        </div>
                                        <div class="am-form-group">
                                            <label class="am-u-sm-3 am-form-label form-require">
                                                微信支付密钥 <span class="tpl-form-line-small-title">APIKEY</span>
                                            </label>
                                            <div class="am-u-sm-9">
                                                <input type="password" class="tpl-form-input" name="wxapp[apikey]"
                                                    value="<?= $info['wxapp']['apikey'] ?>">
                                            </div>
                                        </div>
                                        <div class="am-form-group am-padding-top">
                                            <label class="am-u-sm-3 am-form-label">
                                                apiclient_cert.pem
                                            </label>
                                            <div class="am-u-sm-9">
                                                <textarea rows="6" name="wxapp[cert_pem]"
                                                        placeholder="使用文本编辑器打开apiclient_cert.pem文件，将文件的全部内容复制进来"><?= $info['wxapp']['cert_pem'] ?></textarea>
                                                <small>使用文本编辑器打开apiclient_cert.pem文件，将文件的全部内容复制进来</small>
                                            </div>
                                        </div>
                                        <div class="am-form-group">
                                            <label class="am-u-sm-3 am-form-label">
                                                apiclient_key.pem
                                            </label>
                                            <div class="am-u-sm-9">
                                                <textarea rows="6" name="wxapp[key_pem]"
                                                        placeholder="使用文本编辑器打开apiclient_key.pem文件，将文件的全部内容复制进来"><?= $info['wxapp']['key_pem'] ?></textarea>
                                                <small>使用文本编辑器打开apiclient_key.pem文件，将文件的全部内容复制进来</small>
                                            </div>
                                        </div>
                                    </div>
                                    <!-- 报修 -->
                                    <div class="am-tab-panel am-margin-top-lg" id="tab5">
                                        <div class="am-form-group">
                                            <label class="am-u-sm-3 am-form-label form-require"> 报修模式 </label>
                                            <div class="am-u-sm-9">
                                                <{html_radios1("baoxiu[bx_moshi]",$moshiRadio,$info.baoxiu.bx_moshi)}>
                                            </div>
                                        </div>
                                        <div class="am-form-group">
                                            <label class="am-u-sm-3 am-form-label form-require"> 短信开关 </label>
                                            <div class="am-u-sm-9">
                                                <{html_radios1("baoxiu[sms_status]",$yesRadio,$info.baoxiu.sms_status)}>
                                            </div>
                                        </div>
                                        <div class="am-form-group">
                                            <label class="am-u-sm-3 am-form-label form-require"> 接收人员 </label>
                                            <div class="am-u-sm-9">
                                                <{html_checkboxes1("baoxiu[sms_user]",$userLevels,$info.baoxiu.sms_user)}>
                                                <div class="help-block">
                                                    <small>注：如使用微信支付，则需申请微信支付企业付款到零钱功能</small>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="am-form-group">
                                            <label class="am-u-sm-3 am-form-label form-require"> 短信发送 </label>
                                            <div class="am-u-sm-9">
                                                <{html_checkboxes1("baoxiu[sms_order]",$orderStatus,$info.baoxiu.sms_order)}>
                                                <div class="help-block">
                                                    <small>注：如使用微信支付，则需申请微信支付企业付款到零钱功能</small>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                </div>
                            </div>
                            <div class="am-form-group">
                                <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                    <button type="submit" class="j-submit am-btn am-btn-secondary">提交
                                    </button>
                                </div>
                            </div>
                        </fieldset>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- 图片文件列表模板 -->
<{include file=$module."/public/_template/tpl_file_item.php"}>
<!-- 文件库弹窗 -->
<{include file=$module."/public/_template/file_library.php"}>
<script src="/static/assets/common/js/vue.min.js"></script>
<script src="/static/assets/common/js/ddsort.js"></script>
<script src="/static/assets/common/plugins/umeditor/umeditor.config.js?v=<?= $version ?>"></script>
<script src="/static/assets/common/plugins/umeditor/umeditor.min.js"></script>
<script src="/static/assets/store/js/select.data.js?v=<?= $version ?>"></script>
<script>
    $(function () {

        // 富文本编辑器
        UM.getEditor('container', {
            initialFrameWidth: 575 + 15,
            initialFrameHeight: 200
        });

        // 选择图片
        $('.upload-file').selectImages({
            name: 'site[site_logo]'
            , multiple: false
        });

        // 图片列表拖动
        $('.uploader-list').DDSort({
            target: '.file-item',
            delay: 100, // 延时处理，默认为 50 ms，防止手抖点击 A 链接无效
            floatStyle: {
                'border': '1px solid #ccc',
                'background-color': '#fff'
            }
        });

        /**
         * 表单验证提交
         * @type {*}
         */
        $('#my-form').superForm();

        // 切换默认上传方式
        $("input:radio[name='storage[default]']").change(function (e) {
            $('.form-tab-group').removeClass('active');
            $('#' + e.currentTarget.value).addClass('active');
        });
        $("input:radio[name='sms[status]']").change(function (e) {
            $('.form-tab-group').removeClass('active');
            if(e.currentTarget.value == '1'){
                $('#sms').addClass('active');
            }

        });

        /**
         * 发送测试短信
         */
        $('.j-sendTestMsg').click(function () {
            var msgType = $(this).data('msg-type')
                , formData = {
                AccessKeyId: $('input[name="sms[engine][aliyun][AccessKeyId]"]').val()
                , AccessKeySecret: $('input[name="sms[engine][aliyun][AccessKeySecret]"]').val()
                , sign: $('input[name="sms[engine][aliyun][sign]"]').val()
                , msg_type: msgType
                , template_code: $('input[name="sms[engine][aliyun][' + msgType + '][template_code]"]').val()
                , accept_phone: $('input[name="sms[engine][aliyun][' + msgType + '][accept_phone]"]').val()
            };
            if (!formData.AccessKeyId.length) {
                layer.msg('请填写 AccessKeyId');
                return false;
            }
            if (!formData.AccessKeySecret.length) {
                layer.msg('请填写 AccessKeySecret');
                return false;
            }
            if (!formData.sign.length) {
                layer.msg('请填写 短信签名');
                return false;
            }
            if (!formData.template_code.length) {
                layer.msg('请填写 模板ID');
                return false;
            }
            if (!formData.accept_phone.length) {
                layer.msg('请填写 接收手机号');
                return false;
            }
            layer.confirm('确定要发送测试短信吗', function (index) {
                var load = layer.load();
                var url = "<?= url('setting/smsTest') ?>";
                $.post(url, formData, function (result) {
                    layer.msg(result.msg);
                    layer.close(load);
                });
                layer.close(index);
            });
        });


    });
</script>
